name: "release"
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: false
on:
  release: {}
  schedule:
    - cron: 0 7 * * *
  workflow_dispatch:
    inputs:
      release:
        description: "the version to publish, if you just want to regen the changelog.md set 0.0.0"
        required: true
        type: string
      check:
        required: false
        type: boolean
        default: false
        description: "check that everything is published correctly"
env:
  CHARTS_REPO: "kumahq/charts"
  LEGACY_BINARIES: "centos-amd64,darwin-amd64,darwin-arm64,debian-amd64,darwin-amd64,rhel-amd64,ubuntu-amd64,ubuntu-arm64"
  BINARIES: "darwin-amd64,darwin-arm64,linux-amd64,linux-arm64"
  DOCKER_REPO: "kumahq"
  PULP_URL: "https://download.konghq.com/kuma-binaries-release/"
  DOCKER_IMAGES: "kumactl,kuma-cp,kuma-dp,kuma-init,kuma-cni"
  RELEASE: ${{ inputs.release || '0.0.0' }}
  CHECK: ${{ inputs.check || 'false' }}
  EDITION: kuma
  MIN_VERSION: "1.2.0"
  USE_LABEL_IN_VERSION: "false"
permissions:
  contents: read
jobs:
  release:
    timeout-minutes: 30
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
        with:
          ref: "master"
      - uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
        with:
          go-version-file: go.mod
      - name: install-kuma-ci-tools
        run: |
          echo $(go env GOPATH)/bin >> $GITHUB_PATH
          go install github.com/kumahq/ci-tools/cmd/release-tool@latest
      - name: Generate GitHub app token
        id: github-app-token
        uses: actions/create-github-app-token@f4c6bf6752984b3a29fcc135a5e70eb792c40c6b # v1.8.0
        with:
          app-id: ${{ secrets.APP_ID }}
          private-key: ${{ secrets.APP_PRIVATE_KEY }}
      - name: create-release
        if: env.RELEASE != '0.0.0'
        env:
          GITHUB_TOKEN: ${{ steps.github-app-token.outputs.token }}
        run: |
          release-tool release changelog --repo ${{ github.repository }} --release ${{ env.RELEASE }}
      - name: check-helm
        if: env.RELEASE != '0.0.0' && fromJSON(env.CHECK)
        env:
          GITHUB_TOKEN: ${{ github.token }}
        run: |
          release-tool release helm-chart --repo ${{ github.repository }} --charts-repo ${{ env.CHARTS_REPO }} --release ${{ env.RELEASE }}
      - name: check-pulp-legacy
        env:
          GITHUB_TOKEN: ${{ github.token }}
        if: fromJSON(env.CHECK) && (startsWith(env.RELEASE, '2.1') || startsWith(env.RELEASE, '2.0') || startsWith(env.RELEASE, '1.'))
        run: |
          release-tool release pulp-binaries --repo ${{ github.repository }} --release ${{ env.RELEASE }} --binaries ${{ env.LEGACY_BINARIES }}
      - name: check-pulp
        env:
          GITHUB_TOKEN: ${{ github.token }}
        if: fromJSON(env.CHECK) && !(startsWith(env.RELEASE, '2.1') || startsWith(env.RELEASE, '2.0') || startsWith(env.RELEASE, '1.'))
        run: |
          release-tool release pulp-binaries --repo ${{ github.repository }} --release ${{ env.RELEASE }} --binaries ${{ env.BINARIES }} --base-url ${{ env.PULP_URL }}
      - name: check-docker
        env:
          GITHUB_TOKEN: ${{ github.token }}
        if: fromJSON(env.CHECK)
        run: |
          release-tool release docker --repo ${{ github.repository }} --release ${{ env.RELEASE }} --docker-repo ${{env.DOCKER_REPO }} --images ${{ env.DOCKER_IMAGES }}
      - name: update-active-branches.json
        env:
          GITHUB_TOKEN: ${{ steps.github-app-token.outputs.token }}
        run: |
          release-tool version-file --repo ${{ github.repository }} --active-branches > active-branches.json
      - name: update-versions.yml
        env:
          GITHUB_TOKEN: ${{ steps.github-app-token.outputs.token }}
        run: |
          release-tool version-file --repo ${{ github.repository }} --edition ${{ env.EDITION }} --min-version ${{ env.MIN_VERSION }} --use-label-for-dev=${{ env.USE_LABEL_IN_VERSION }} > versions.yml
      - name: update-CHANGELOG.md
        env:
          GITHUB_TOKEN: ${{ steps.github-app-token.outputs.token }}
        run: |
          release-tool changelog.md --repo ${{ github.repository }} > CHANGELOG.md
      - name: "Create Pull Request"
        uses: peter-evans/create-pull-request@b1ddad2c994a25fbc81a28b3ec0e368bb2021c50 # v6.0.0
        with:
          commit-message: "docs(CHANGELOG.md): updating changelog and version files"
          signoff: true
          branch: chore/update-changelog
          base: master
          delete-branch: true
          title: "docs(CHANGELOG.md): updating changelog and version files"
          draft: false
          labels: ci/skip-test,ci/auto-merge
          token: ${{ steps.github-app-token.outputs.token }}
          committer: kumahq[bot] <110050114+kumahq[bot]@users.noreply.github.com>
          author: kumahq[bot] <110050114+kumahq[bot]@users.noreply.github.com>
